<template>
  <page-header-wrapper>
    <page-tab-list>
      <div class="table-page-search-box">
        <a-form layout="inline">
          <a-row :gutter="24">
            <a-col :md="8" :sm="24">
              <a-form-item label="订单号">
                <a-input placeholder="请输入订单号" v-model="queryParam.order_no"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="购买人">
                <a-input placeholder="请输入购买人" v-model="queryParam.name"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="">
                <a-button type="primary" @click="getList">查询</a-button>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </page-tab-list>
    <a-card :bordered="false">
      <a-table
        :rowKey="
          (r, i) => {
            return i
          }
        "
        :pagination="{
          total: this.totalCount,
          showSizeChanger: false,
          onChange: this.tablePageChange,
        }"
        :columns="columns"
        :data-source="list"
        :scroll="{ x: 'max-content' }"
      >
        <div slot="name" slot-scope="text, record">
          <div class="name">
            <div class="pic">
              <img :src="record.goods_list[0].pic" alt="" />
            </div>
            <div class="info">
              <span>{{ record.goods_list[0].goods_name }}</span>
              <span>规格：{{ record.goods_list[0] | sku }}</span>
            </div>
          </div>
        </div>
        <span slot="total_price" slot-scope="text"> ¥{{ text || '0.00' }} </span>
        <span slot="mobile" slot-scope="scope"> {{ scope.name }} / {{ scope.mobile }} </span>
        <span slot="audit_time" slot-scope="text">
          {{ text > 0 ? $moment(text * 1000).format('YYYY-MM-DD HH:mm:ss') : '-' }}
        </span>
        <div slot="buy" slot-scope="scope">
          <div>{{ scope.nickname }}</div>
          <div>{{ scope.created_at || '-' }}</div>
        </div>

        <div slot="expandedRowRender" slot-scope="record">
          <div class="name" style="padding: 10px 0" v-for="(item, index) in record.goods_list" :key="index">
            <div class="pic">
              <img :src="item.pic" alt="" />
            </div>
            <div class="info">
              <span>{{ item.goods_name }}</span>
              <span>规格：{{ item | sku }}</span>
            </div>
          </div>
        </div>
      </a-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { teamOrderList } from '@/api/shareholder'
const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
  },
  {
    title: '订单号',
    dataIndex: 'order_no',
  },
  {
    title: '订单金额',
    dataIndex: 'total_price',
    scopedSlots: {
      customRender: 'total_price',
    },
  },
  {
    title: '商品信息',
    scopedSlots: {
      customRender: 'name',
    },
    width: 250,
  },
  {
    title: '购买人/购买时间',
    scopedSlots: {
      customRender: 'buy',
    },
  },
]
export default {
  data() {
    return {
      queryParam: {
        order_no: null,
        name: null,
        pageNo: 1,
        pageSize: 10,
      },
      list: [],
      columns,
      totalCount: 0,
      user_id: undefined,
    }
  },
  filters: {
    sku(e) {
      let sku = JSON.parse(e.attr)
      return sku.map((e) => e.attr_name).join() || '默认'
    },
  },
  methods: {
    async getList() {
      const hide = this.$message.loading('加载中', 0)
      const { queryParam, user_id } = this
      const res = await teamOrderList({ ...queryParam, user_id })
      if (res.code == 0) {
        this.totalCount = res.data.totalCount
        this.list = res.data.list
      }
      hide()
    },

    tablePageChange(e) {
      this.queryParam.pageNo = e
      this.getList()
    },
  },
  mounted() {
    try {
      let { user_id } = this.$route.query
      this.user_id = user_id
    } catch (error) {}
    this.getList()
  },
}
</script>

<style lang="less" scoped>
.search {
  /deep/ .ant-card-body {
    padding-top: 0 !important;
    padding-bottom: 14px !important;
  }
}
.searchBox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .ant-input-affix-wrapper {
    width: 220px;
    margin-top: 14px;
    margin-right: 20px;
  }
  .select {
    display: flex;
    align-items: center;
    margin-top: 14px;
    margin-right: 20px;
  }
  .ant-btn {
    margin-top: 14px;
  }
}
.name {
  display: flex;
  align-items: center;
  .pic {
    width: 48px;
    min-width: 48px;
    height: 48px;
    border-radius: 4px;
    overflow: hidden;
    margin-right: 24px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .info {
    flex: auto;
    width: 0;
    display: flex;
    flex-direction: column;
    font-size: 14px;
    span {
      width: 100%;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    span:nth-child(2) {
      color: rgba(0, 0, 0, 0.45);
      margin-top: 6px;
    }
  }
}
.action {
  display: flex;
  align-items: center;
  .line {
    width: 1px;
    height: 14px;
    background-color: #d8d8d8;
  }
}
.level_one_count {
  text-decoration: underline;
  cursor: pointer;
  color: #ff4400;
}
</style>
